package com.yuhuihui.common.exception;

import com.yuhuihui.common.annotation.mvc.SimpleResponseBody;
import com.yuhuihui.common.domain.result.ResponseResult;
import com.yuhuihui.common.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 通用异常捕获
 *
 * @author yuhh
 * @date 2023-05-25 14:55:02
 */
public class CommonExceptionHandler {

    Logger logger = LoggerFactory.getLogger(CommonExceptionHandler.class);

    @ExceptionHandler(value = IoCommonException.class)
    @SimpleResponseBody
    public ResponseResult<String> ioCommonException(IoCommonException e) {
        logger.error(e.getMessage(), e);
        return ResultUtil.error(e.getMessage());
    }

    @ExceptionHandler(value = CommonException.class)
    @SimpleResponseBody
    public ResponseResult<String> commonException(CommonException e) {
        logger.error(e.getMessage(), e);
        return ResultUtil.error(e.getMessage());
    }
}
